const { BusiError, SysError } = require('../exception/exception');
const payService = require("../service/PayService");
const redisConst = require("../const/redisConst");
const redis = require("../dao/redis");

class PayRechargeQueryJob {
    constructor() {
    }

    async query(date){
        const limitKey = redisConst.PAY_RECHARGE_QUERY_LOCK + "_LOCK";
        let ok = await redis.lock(limitKey, 1, 50);
        if (!ok){
            return;
        }
        console.logw("pay recharge query start>>>>>>>>>>>>>>>>>>>>>>");

        let res = await payService.queryOrdersByOrderType("OT001");
        for (let i = 0; i < res.length; i++) {
            let item = res[i];
            try {
                await payService.getService(item.pay_channel).payQuery(item.out_trade_no);
            }catch (e) {
                console.logw("pay query err:", item.out_trade_no);
                console.log(e);
                continue;
            }
            console.logw("pay query success:", item.out_trade_no);
        }

        console.logw("pay recharge query end<<<<<<<<<<<<<<<<<<<<<<<<");
    }
}


let payRechargeQueryJob = new PayRechargeQueryJob();
module.exports = payRechargeQueryJob;